package com.RedRiver.hospitalsystem.finance_service.service.impl;

import com.RedRiver.hospitalsystem.finance_service.common.WoniuxyBeanCopyUtil;
import com.RedRiver.hospitalsystem.finance_service.common.exception.PaymethodException;
import com.RedRiver.hospitalsystem.finance_service.infra.mapper.PaymethodMapper;
import com.RedRiver.hospitalsystem.finance_service.infra.model.Paymethod;
import com.RedRiver.hospitalsystem.finance_service.service.PaymethodService;
import com.RedRiver.hospitalsystem.finance_service.service.info.PaymethodInfo;
import com.RedRiver.hospitalsystem.finance_service.service.info.PaymethodInfoList;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 龙世超
 * @since 2022-04-26
 */
@Service
public class PaymethodServiceImpl extends ServiceImpl<PaymethodMapper, Paymethod> implements PaymethodService {

    @Resource
    private PaymethodMapper paymethodMapper;
    @Override
    public PaymethodInfoList findAll() {
        PaymethodInfoList paymethodInfoList = new PaymethodInfoList();
        ArrayList<PaymethodInfo> paymethodInfos = new ArrayList<>();
        List<Paymethod> paymethods = paymethodMapper.selectList(null);
        if (null==paymethods||paymethods.size()==0)throw new PaymethodException(50001,"没有缴费方式");
        for (Paymethod paymethod : paymethods) {
            PaymethodInfo copyone = WoniuxyBeanCopyUtil.copyone(paymethod, PaymethodInfo.class);
            paymethodInfos.add(copyone);
        }
        paymethodInfoList.setList(paymethodInfos);
        return paymethodInfoList;
    }
}
